<!--
auth: 徐剑锋
-->
<html>
<head>
    <link rel="stylesheet" href="<?php echo IMG_PATH ?>admin/common.css?<?php echo STATIC_VER ?>">
    <link rel="stylesheet" href="<?php echo IMG_PATH ?>admin/bootstrap.min.css">
    <script>SITE_PATH='<?php echo SITE_PATH ?>';</script>
    <title>监控订单 - 千纸鹤管理平台</title>
    <style>
        th{font-size: 18px;text-align: center;}
        td{font-size: 16px;text-align: left;padding:5px 10px;;}
        tr:nth-child(odd){background:#F0F8FF;}
        td:hover{};

        .showpage{width:100%; height:30px;text-align:center; line-height: 30px;float:left;font-size:16px;margin:10px 0;}

        .showpage a , .showpage .current{ border:1px dashed #f1f4f6;font-size:14px; font-family:arial; margin:0 1px;}
        .showpage a ,  .current{ padding:2px 6px;}
        .showpage .current, .showpage a:hover{ border:1px solid blue;text-decoration:none;}
    </style>
</head>
<body>

<?php
echo $header;
date_default_timezone_set('PRC');
?>

<div id="body" style="width:100%;">
    <div style="font-size:18px;margin:5px 0;">当前位置：报表＞＞财务>>每日统计（<?php echo isset($realname)?$realname:'';?>）</div>
    <a style="font-size:18px;margin:5px 0;cursor:pointer;" id="toback"><<返回</a>
    <form action="/admin/finances/financesDetail" method="get" id="searchForm">
        <div style="width:100%;height:60px; border-bottom:1px solid gray;">

            <div style="height:60px;width:74%;float:left;">

                <div style="height:33px;width:110%;" >
                    <div style="float:left;font-size:18px;margin:5px 0;">搜索条件>>  </div>
                    <div style="float:left;margin:5px 15px;font-size:16px;">时间：<input type="text" name="searchDate"id="searchDate" onClick="WdatePicker();" autocomplete="false" value="<?php echo isset($_GET['searchDate'])?$_GET['searchDate']:'';?>"/></div>
                    <input type="hidden" name="wid" value="<?php echo isset($_GET['wid'])?$_GET['wid']:'';?>"/>
                    <input type="hidden" name="wname" value="<?php echo isset($_GET['wname'])?$_GET['wname']:'';?>"/>
                    <div style="float:left;"><input type="submit"  class="btn btn-primary" value="搜索" /> </div>
                    <div style="float:left;margin-left:20px;">
                        <a class="btn btn-info" href="/admin/finances/financesDetail?wid=<?php echo $_GET['wid']?>&wname=<?php echo $_GET['wname']?>">清空</a>
                    </div>
                </div>
            </div>
    </form>

</div>

<?php if(isset($errors) || (isset($_GET['err']) && $errors=$_GET['err'])){ ?>
    <div class="alert alert-error"style="width:40%;padding: 15px 0;  text-align: center; color: red;background: pink;margin-left: 29%;margin-bottom: 10px;">
        <?php echo $errors;?>
    </div>
<?php }?>

<div class="showpage"><?php echo isset($pages)?$pages:'';?></div>
<div style="width:100%;min-height:100%;">
<?php
if(isset($datas) && count($datas)) {
    $i = isset($_GET['page']) ? ($_GET['page'] - 1) * 3 + 1 : 1;
    foreach($datas as $data) { ?>
        <div style="font-size: 16px;margin-top:30px;">时间：<?php echo '<span class="everyDate">'.$data['days'].'</span>'; ?>&nbsp;&nbsp;合计：<?php echo ($data['totalPrice']>0 ? '<span style="color:green;font-weight:bold;">'.$data['totalPrice'].'</span>':'<span style="color:red;font-weight:bold;">'.$data['totalPrice'].'</span>') ?></div>

        <table width="96%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #D4D4D4;">
            <tbody id="listTBody" class="<?php echo $data['days'];?>">
            <tr>
                <td>收件数量：<span class="getNum"></span>件</td>
                <td>派件数量：<span class="sendNum"></span>件</td>
                <td>中心扫描：<span class="totalNum"></span>件<?php echo (isset($_GET['wid']) && ($_GET['wid']==179||$_GET['wid']==373))?" ($centerPrice 元/件)":'';?></td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>中转费：<span class="transfer_charge"></span>元 <button class="toTranferList"style="margin-left:10px;"d="<?php echo $data['days'];?>">查看详情</button></td>
                <td>派件费：<span class="send_charge"></span>元<button class="toSendList"style="margin-left:10px;" d="<?php echo $data['days'];?>">查看详情</button></td>
                <td>扫描费：<span class="center_charge"></span>元<button class="toScanList"style="margin-left:10px;"d="<?php echo $data['days'];?>">查看详情</button></td>
                <td>充值：<span class="prepaid_charge"></span>元<button class="toPrepaid"style="margin-left:10px;"d="<?php echo $data['days'];?>">查看详情</button></td>
            </tr>

            </tbody>
        </table>

        <div class="<?php echo $data['days'];?>_1  pList" style="width:100%;border:1px solid gray;border-radius:10px;display:none;margin-top:10px;">
            <div style="font-size: 18px;padding:5px;color:blue;">充值详情列表：共<span class="prepaidNum" d="<?php echo $data['days'];?>"></span>次</div>
            <div class="prepaidList" style="width:100%;"></div>
        </div>

        <div class="<?php echo $data['days'];?>_2  sList" style="width:100%;border:1px solid gray;border-radius:10px;display:none;margin-top:10px;">
            <div style="font-size: 18px;padding:5px;color:blue;">派件详情列表：共<span class="sendNum" d="<?php echo $data['days'];?>"></span>件&nbsp;&nbsp;(注：以下ID和名称非一&nbsp;一对应关系)</div>
            <div class="sendList" style="width:100%;"></div>
        </div>

        <div class="<?php echo $data['days'];?>_3  tList" style="width:100%;border:1px solid gray;border-radius:10px;display:none;margin-top:10px;">
            <div style="font-size: 18px;padding:5px;color:blue;">中转详情列表：共<span class="tranferNum" d="<?php echo $data['days'];?>"></span>件</div>
            <div class="tranferList" style="width:100%;"></div>
        </div>

        <div class="<?php echo $data['days'];?>_4  scList" style="width:100%;border:1px solid gray;border-radius:10px;display:none;margin-top:10px;">
            <div style="font-size: 18px;padding:5px;color:blue;">扫描详情列表：共<span class="scanNum" d="<?php echo $data['days'];?>"></span>件</div>
            <div class="scanList" style="width:100%;"></div>
        </div>

    <?php }
}else {
    echo '<div style="width:100%;text-align:center;font-size;20px;">查无数据</div>';
}
?>
    <div class="showpage" style="margin-top:15px;"><?php echo isset($pages)?$pages:'';?></div>
</div>

<script src="http://static.caocaod.com/libs/jquery/jquery-2.2.3.min.js"></script>
<script src="<?php echo IMG_PATH ?>admin/common.js?<?php echo STATIC_VER ?>"></script>
<script src="<?php echo IMG_PATH ?>admin/bootstrap.min.js"></script>
<script  src="<?php echo IMG_PATH ?>com/My97DatePicker/WdatePicker.js"></script>
<script>
    $('.num,.first,.prev,.next,.end').click(function() {
        window.location.href = SITE_PATH+'admin/finances/financesDetail?page='+$(this).attr('page')+'&wid=<?php echo $_GET['wid'];?>&wname=<?php echo $_GET['wname'];?>';
    })

    $('#toback').click(function() {
        window.location.href= SITE_PATH + 'admin/finances/main';
    })

    $(function() {
        var wid = <?php echo isset($_GET['wid']) && trim($_GET['wid']) ? $_GET['wid']:'';?>;
        if(wid) {
            $('.everyDate').each(function (i) {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fdate': $(this).html(), 'wid':wid},
                    url: SITE_PATH + 'admin/finances/queryEveryDate',
                    success: function (msg) {
                        $('.' + msg['date'] + ' .getNum').html(msg['jdatas']['getNum']);
                        $('.' + msg['date'] + ' .sendNum').html(msg['jdatas']['sendNum']);
                        $('.' + msg['date'] + ' .totalNum').html(msg['jdatas']['totalNum']);
                        $('.' + msg['date'] + ' .transfer_charge').html(msg['jdatas']['transfer_charge']);
                        $('.' + msg['date'] + ' .center_charge').html(msg['jdatas']['center_charge']);
                        $('.' + msg['date'] + ' .send_charge').html(msg['jdatas']['send_charge']);
                        $('.' + msg['date'] + ' .prepaid_charge').html(msg['jdatas']['prepaid_charge']);
                    }
                })
            })
        }else {
            window.location.href = SITE_PATH + 'admin/finances/main?err=无查询ID传递';
        }

        $('.toSendList').click(function() {
            if($(this).html()=='查看详情') {
                var that=$(this);
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fdate': $(this).attr('d'), 'wid': wid},
                    url: SITE_PATH + 'admin/finances/sendList',
                    success: function (msg) {
                        if (msg['result'] == 1) {
                            $(that).html('收起详情');
                            var $count = 0, str = '<table width="100%"><tr><th>被派送人</th><th>费用</th><th>件数</th><th>派送的件ID</th></tr>';
                            if (Object.keys(msg['sendList']).length) {
                                for (var i in msg['sendList']) {
                                    $count += parseInt(msg['sendList'][i]['piece_count']);
                                    str += '<tr><td style="word-break:break-all;max-width:28%;">' + msg['sendList'][i]['worked_id'] + '<br>' + msg['sendList'][i]['realnames'] + '</td><td style="text-align:center;">' + msg['sendList'][i]['price'] + '元</td><td style="text-align:center;">' + msg['sendList'][i]['piece_count'] + '件</td><td style="word-break:break-all;max-width:65%;width:65%;"><div>' + msg['sendList'][i]['piece_ids'] + '</div><button pids="' + msg['sendList'][i]['piece_ids'] + '"class="queryPcode">查看件码</button><div style="color:orange;max-width:100%;word-break:normal;"></div></td></tr>';
                                }
                            }else {
                                str += '<tr><td colspan="4"style="text-align:center">查无数据</td></tr>';
                            }
                            str += '</table>';

                            $('.' + msg['date'] + '_2 .sendNum').html($count);
                            $('.' + msg['date'] + '_2 .sendList').html(str);

                            $('.' + msg['date'] + '_2').slideDown();
                        }else
                            alert('查询失败:'+msg['msg']);
                    }
                });
            }else {
                $('.' + $(this).attr('d') + '_2').slideUp();
                $(this).html('查看详情');
            }
        });

        function queryPcode(this1) {
            var pids = $(this1).attr('pids'),that=$(this1)
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {'pids': pids},
                url: SITE_PATH + 'admin/finances/queryPieceCode',
                success: function (msg) {
                    $(that).css('display','none');
                    $(that).next('div').html(msg['pieceCodes']);
                }
            });
        }

        $('.sList').on('click','.queryPcode',function() {
            queryPcode(this);
        });

        $('.tList').on('click','.queryPcode',function() {
            queryPcode(this);
        });


        $('.toTranferList').click(function() {
            if($(this).html()=='查看详情') {
                var that=$(this);
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fdate': $(this).attr('d'), 'wid': wid},
                    url: SITE_PATH + 'admin/finances/tranferList',
                    success: function (msg) {
                        if(msg['result']==1) {
                            $(that).html('收起详情');
                            var $count = 0, str = '<table width="100%"><tr><th>中转人ID</th><th>中转人名</th><th>中转费用</th><th>中转件数</th><th>中转件ID</th></tr>';
                            if (Object.keys(msg['tranferList']).length) {
                                for (var i in msg['tranferList']) {
                                    var v = msg['tranferList'][i]
                                    $count += parseInt(v['piece_count']);
                                    str += '<tr><td style="text-align:center;">' + v['worked_id'] + '</td><td style="text-align:center;">' + v['realname'] + '</td><td style="text-align:center;">' + v['price'] + '元</td><td style="text-align:center;">' + v['piece_count'] + '件</td><td style="word-break:break-all;max-width:65%;width:65%;"><div>' + v['piece_ids'] + '</div><button pids="' + v['piece_ids'] + '"class="queryPcode">查看件码</button><div style="color:orange;max-width:100%;word-break:normal;"></div></td></tr>';

                                }
                            }else {
                                str += '<tr><td colspan="5"style="text-align:center">查无数据</td></tr>';
                            }
                            str += '</table>';

                            $('.' + msg['date'] + '_3 .tranferNum').html($count);
                            $('.' + msg['date'] + '_3 .tranferList').html(str);

                            $('.' + msg['date'] + '_3').slideDown();

                        }else
                            alert('查询失败:'+msg['msg']);
                    }
                });
            }else {
                $('.' + $(this).attr('d') + '_3').slideUp();
                $(this).html('查看详情');
            }
        })


        $('.toPrepaid').click(function() {
            if($(this).html()=='查看详情') {
                var that=$(this);
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fdate': $(this).attr('d'), 'wid': wid},
                    url: SITE_PATH + 'admin/finances/prepaidList',
                    success: function (msg) {
                        if(msg['result']==1) {
                            $(that).html('收起详情');
                            var $count = 0;
                            var str = '<table width="100%"><tr><th>姓名<span style="font-weight:normal"></span></th><th>充值金额</th><th>时间</th></tr>';
                            if (Object.keys(msg['prepaidList']).length) {
                                for (var i in msg['prepaidList']) {
                                    var v=msg['prepaidList'][i];
                                    ++$count;
                                    str += '<tr><td style="word-break:break-all;max-width:28%;">' + v['realname'] + '</td><td style="text-align:center;">' + v['price'] + '元</td><td style="text-align:center;">' + v['time_add'] + '</td></tr>';

                                }
                            }else {
                                str += '<tr><td colspan="3"style="text-align:center">查无数据</td></tr>';
                            }
                            str += '</table>';
                            $('.' + msg['date'] + '_1 .prepaidNum').html($count);
                            $('.' + msg['date'] + '_1 .prepaidList').html(str);

                            $('.' + msg['date'] + '_1').slideDown();
                        }else
                            alert('查询失败:'+msg['msg']);
                    }
                });
            }else {
                $('.' + $(this).attr('d') + '_1').slideUp();
                $(this).html('查看详情');
            }
        })


        $('.toScanList').click(function() {
            if($(this).html()=='查看详情') {
                var that=$(this);
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fdate': $(this).attr('d'), 'wid': wid},
                    url: SITE_PATH + 'admin/finances/scanList',
                    success: function (msg) {
                        if(msg['result']==1) {
                            $(that).html('收起详情');
                            var sum = 0;
                            var str = '<table style="width:100%"><tr><th>被扫描人<span style="font-weight:normal"></span></th><th>费用</th><th>件数</th><th>所扫描的件</th></tr>';
                            if (Object.keys(msg['scanList']).length) {
                                for (var i in msg['scanList']) {
                                    sum += parseInt(msg['scanList'][i]['piece_count']);
                                    str += '<tr><td style="word-break:break-all;max-width:28%;">' + msg['scanList'][i]['worked_id'] + '<br>' + msg['scanList'][i]['realnames'] + '</td><td style="text-align:center;">' + msg['scanList'][i]['price'] + '元</td><td style="text-align:center;">' + msg['scanList'][i]['piece_count'] + '件</td><td style="word-break:break-all;max-width:65%;width:65%;"><div style="color:orange">' + msg['scanList'][i]['piece_ids'] + '</div></td></tr>';

                                }
                            } else {
                                str += '<tr><td colspan="4"style="text-align:center">查无数据</td></tr>';
                            }
                            str += '</table>';

                            $('.' + msg['date'] + '_4 .scanNum').html(sum);
                            $('.' + msg['date'] + '_4 .scanList').html(str);

                            $('.' + msg['date'] + '_4').slideDown();
                        }else {
                            alert('查询失败:'+msg['msg']);
                        }

                    }
                });
            }else {
                $('.' + $(this).attr('d') + '_4').slideUp();
                $(this).html('查看详情');
            }
        })


        $('#searchForm').submit(function() {
            if($('#searchDate').val().trim()=='') {
                alert('搜索条件不能为空');
                return false;
            }
        })
    })

</script>

</body>
</html>